//
// Created by Ivor_ on 2024/1/30.
//

#ifndef HOSTILE_LINKEDLIST_H
#define HOSTILE_LINKEDLIST_H

// [Warning]: Because of the "printf" in <stdio.h>, function printListLLN is ill-defined, you may change into your dataType before use it!

#include <malloc.h>
#include <string.h>
#include <stdio.h>

typedef struct ListNode {
    void* data;
    struct ListNode* next;
} LIST_NODE;

typedef struct {
    int len;
    LIST_NODE* dummyHead;
} LINKED_LIST;

// LIST_NODE* createNodeLLN(const void* _data, size_t dataSize, LIST_NODE* _next); Forbid to use for user!
LINKED_LIST* createListLLN();
//void freeNodeLLN(LIST_NODE* nodeObj); Forbid to use for user!
void freeListLLN(LINKED_LIST* listObj);

void insertNodeLLN(LINKED_LIST* listObj, int index, const void* _data, size_t dataSize);
void insertToNextNodeLLN(LINKED_LIST* listObj, LIST_NODE* nodeObj, const void* _data, size_t dataSize);
void removeNodeLLN(LINKED_LIST* listObj, int index);
void removeNextNodeLLN(LINKED_LIST* listObj, LIST_NODE* nodeObj);
LIST_NODE* findNodeLLN(const LINKED_LIST* listObj, const void* _data, size_t dataSize);
LIST_NODE* getNodeLLN(const LINKED_LIST* listObj, int index);
void updateNodeLLN(LINKED_LIST* listObj, int index, const void* _data, size_t dataSize);
void updateThisNodeLLN(LIST_NODE* nodeObj, const void* _data, size_t dataSize);
void printListLLN(const LINKED_LIST* listObj, const char* format, FILE* io);

#endif //HOSTILE_LINKEDLIST_H
